<!doctype html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>卡密批量增加</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" th:href="@{/static/css/font.css}">
    <link rel="stylesheet" th:href="@{/static/css/xadmin.css}">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script th:src="@{/static/js/html5.min.js}" charset="UTF-8" src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script th:src="@{/static/js/respond.min.js}" charset="UTF-8" src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="layui-layout-body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>卡密批号增加</legend>
</fieldset>
<form class="layui-form layui-form-pane" lay-filter="example" >
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="title" name="name" autocomplete="off" placeholder="请输入本次生成的名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-block">
            <input type="number" lay-verify="number" name="number" autocomplete="off" placeholder="请输入数量" class="layui-input">
        </div>
    </div>
    </div>

    <div class="layui-form-item layui-hide" >
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal" id="close">关闭</button>
            <button type="submit" class="layui-btn" id="submit-btn" lay-submit="" lay-filter="submit-btn">立即提交</button>
        </div>
    </div>
</form>


</body>
<script th:inline="javascript">
    var ctx = [[@{/}]]
    //var type = /*[[${type}]]*/    //获取model中的值
</script>

<script th:inline="none">
    layui.use(['form', 'layedit'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,$ = layui.jquery
            ,layedit = layui.layedit;

        //自定义验证规则
        form.verify({
            title: function(value){
                if("" ==value){
                    return '请输入！！！';
                }
            },
            number: function(value){
                if(value > 200){
                    return '最多批号增加200!!!';
                }
            }

        });

        //监听提交
        form.on('submit(submit-btn)', function(data){

            $.ajax({
                type: "POST",
                url: ctx + "adds",
                contentType: "application/json", //必须有
                dataType: "json", //表示返回值类型，不必须
                data: JSON.stringify(data.field),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
                success: function (jsonResult) {
                    if(jsonResult.code == 200){
                        let html = "<textarea class=\"layui-textarea\" style=' height: 100%;'>";
                        $.each(jsonResult.data, function (index, thisData) {
                            html += thisData.value + "\n";
                        });
                        html += "</textarea>";
                        parent.layer.open({
                            type: 1
                            ,title:"卡密批号列表  Ctrl+A全选"
                            ,area: ['20%','80%']
                            ,btnAlign: 'c' //按钮居中
                            ,content: html
                        });
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭s
                    }else {
                        layer.msg(jsonResult.msg);
                    }
                }
            });

            return false;
        });

        //关闭
        layui.$('#close').on('click', function(){
            //当你在iframe页面关闭自身时
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

    });



</script>

</html>